package top.heliming.springbootes;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.elasticsearch.common.settings.Settings;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

/**
 * description: //TODO
 *
 * @author: heliming
 * @date:2019/05/19 下午 8:51
 */
@Configuration
public class MyConfig {

    @Bean
    public TransportClient client() throws UnknownHostException {
        InetSocketTransportAddress node = new InetSocketTransportAddress(
                InetAddress.getByName("localhost"),9300
        );//tcp端口是9300不是9200
        Settings settings = Settings.builder().put("cluster.name","xiaoming").build();
        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(node);
       // client.addTransportAddress(node2); 可以注册多个节点
        return  client;
    }


}
